package com.len.mapper;

import com.len.base.BaseMapper;
import com.len.base.CurrentUser;
import com.len.entity.SpOrder;
import com.len.entity.SysUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

public interface SpOrderMapper extends BaseMapper<SpOrder,String> {
    @Update("update sp_order set TB_ORDER_STATUS=2 where ID= #{orderId}")
    void checkData(String orderId);
    @Update("update sys_user set password=#{password} where ID= #{orderId}")
    void changePwd(String orderId,String password);
    @Select("select real_name as TB_USERNAME,TB_IDCARD from sys_user where id = #{id}")
    Map getPerson(String id);
    @Select("select * from sys_user where id = #{id}")
    Map getZFPerson(String id);
    @Insert("insert into sys_user (username,password,TB_JSPERSON,JSR,ID) values (#{username},#{password},#{TB_JSPERSON},#{JSR},#{id})")
    void insertUser(SysUser order);
    void insert1(SpOrder order);
    @Update("update sys_user set real_name = #{realName},TB_IDCARD=#{idCard} where id = #{id}")
    void updateUser(String realName, String idCard,String id);
    @Update("update sys_user set TB_ZFB_FILEPATH = #{TB_ZFB_FILEPATH},TB_WX_FILEPATH=#{TB_WX_FILEPATH},TB_BACKCARD=#{TB_BACKCARD},TB_BACKNAME=#{TB_BACKNAME},TB_ZFB_USERNAME=#{TB_ZFB_USERNAME},TB_ZFB_NUMBER=#{TB_ZFB_NUMBER} where id = #{id}")
    void updateUserZf(CurrentUser user);
    void update(SpOrder order);
    @Update("update sys_user set GMCS = #{cs} where id = #{id}")
    void subgmcs(String cs,String id);
    /**
     * 查询所有订单
     */
    @Select("SELECT * FROM SP_ORDER WHERE FK_ID = #{userId}")
    List<SpOrder> showll(String userId);

    /**
     * 查询所有订单
     */
    @Select("SELECT * FROM SP_ORDER WHERE TB_ORDER_STATE = 5  ")
    List<SpOrder> show5();

    /**
     * 查询所有订单
     */
    @Select("SELECT * FROM SP_ORDER WHERE TB_NUMBER = #{byNum}  ")
    SpOrder byNum(String byNum);
    /**
     * 查询所有订单
     */
    SpOrder queryById(String id);
    /**
     * 查询所有订单
     */
    @Select("SELECT * FROM sys_user WHERE TB_BZJ_PRICE is not null  ")
    List<CurrentUser> show6();
    /**
     * 查询所有订单
     */
    @Select("SELECT * FROM SP_ORDER WHERE ID = #{id}")
    SpOrder showlid(String id);
    /**
     * 查询所有订单
     */
    @Select("SELECT * FROM SP_ORDER  t1 left join sp_goods t2 on t1.TB_GOODSID =t2.ID left join sys_user t3 on t1.BY TB_ADDTIME DESC")
    List<SpOrder> showall();
    @Select("SELECT * FROM SP_ORDER WHERE TB_BUYER = #{username}")
    List<SpOrder>  showMyOrder1(String username);
    @Select("SELECT t1.*, t2.*,t3.* FROM SP_ORDER t1 LEFT JOIN sp_goods t2 ON t1.TB_GOODSID =t2.ID LEFT JOIN SYS_USER t3 ON  t1.TB_SELLER = t3.username  WHERE  TB_SELLER = #{username}")
    List<Map>  showMyOrder2(String username);
    @Select("SELECT t1.*, t2.*,t3.* FROM SP_ORDER t1 LEFT JOIN sp_goods t2 ON t1.TB_GOODSID =t2.ID LEFT JOIN SYS_USER t3 ON  t1.TB_SELLER = t3.username  WHERE  TB_NUMBER = #{data}")
    List<Map>  showMyOrder3(String username);
    @Select("SELECT COUNT(*)   FROM sp_order WHERE TB_BUYER = #{username}")
    Integer  showTB_BUYER(String username);
    @Select("SELECT COUNT(*)   FROM sp_order WHERE TB_SELLER = #{username}")
    Integer  showTB_SELLER(String username);

    @Select("SELECT t1.*, t2.*,t3.* FROM SP_ORDER t1 LEFT JOIN sp_goods t2 ON t1.TB_GOODSID =t2.ID LEFT JOIN SYS_USER t3 ON  t1.TB_SELLER = t3.username  WHERE  TB_BUYER =  #{username} order by t1.TB_ADDTIME desc")
    List<Map> showDataTB_BUYER(String username);

    @Select("SELECT t1.*, t2.*,t3.* FROM SP_ORDER t1 LEFT JOIN sp_goods t2 ON t1.TB_GOODSID =t2.ID LEFT JOIN SYS_USER t3 ON  t1.TB_SELLER = t3.username  WHERE  TB_SELLER = #{username} order by t1.TB_ADDTIME desc")
    List<Map>  showDataTB_SELLER(String username);
    /**
     * 倒计时
     */
    @Select(" SELECT TB_ADDTIME FROM  SP_ORDER WHERE   TB_BUYER = #{username}")
     Timestamp[] Time(String username);
    @Select(" SELECT TB_ADDTIME FROM  SP_ORDER WHERE   TB_BUYER = #{username} and TB_ADDTIME > #{timr}  ORDER BY  TB_ADDTIME ASC  ")
    Timestamp[] Time1(String username,Timestamp timr);
    /**
     * 分页查询所有订单
     */
    List<Map> selectDataByPage(SpOrder t);

    @Select("SELECT t1.*, t2.*,t3.* FROM SP_ORDER t1 LEFT JOIN sp_goods t2 ON t1.TB_GOODSID =t2.ID LEFT JOIN SYS_USER t3 ON  t1.TB_SELLER = t3.username  WHERE  TB_SELLER = #{username} OR TB_BUYER == #{username} order by t1.TB_ADDTIME desc")
    List<Map>  showData(String username);
    /**
     * 委托代賣
     */
    @Select("SELECT t1.*, t2.*,t3.* FROM SP_ORDER t1 LEFT JOIN sp_goods t2 ON t1.TB_GOODSID =t2.ID LEFT JOIN SYS_USER t3 ON  t1.TB_SELLER = t3.username  WHERE TB_ORDER_STATE = 3 and TB_SELLER = #{username} order by t1.TB_ADDTIME desc")
    List<Map>  showZfcg(String username);
    /**
     * 交易成功
     */
    @Select("SELECT t1.*, t2.*,t3.* FROM SP_ORDER t1 LEFT JOIN sp_goods t2 ON t1.TB_GOODSID =t2.ID LEFT JOIN SYS_USER t3 ON  t1.TB_SELLER = t3.username  WHERE TB_ORDER_STATE = 2 and TB_GOODS_STATUS  = 4 and (TB_BUYER = #{username} OR TB_SELLER = #{username}) order by t1.TB_ADDTIME desc")
    List<Map>  showJycg(String username);
    /**
     * 确认收货
     */
    @Select("SELECT t1.*, t2.*,t3.* FROM SP_ORDER t1 LEFT JOIN sp_goods t2 ON t1.TB_GOODSID =t2.ID LEFT JOIN SYS_USER t3 ON  t1.TB_SELLER = t3.username  WHERE TB_ORDER_STATE = 6  and TB_SELLER = #{username} order by t1.TB_ADDTIME desc")
    List<Map> showQrsh (String username);

/**
 * 确认订单
 */
    @Select("SELECT t1.*, t2.*,t3.* FROM SP_ORDER t1 LEFT JOIN sp_goods t2 ON t1.TB_GOODSID =t2.ID LEFT JOIN SYS_USER t3 ON  t1.TB_SELLER = t3.username  WHERE T1.ID = #{ID} order by t1.TB_ADDTIME desc")

    List<Map> QrOrder (String ID);
    /**
     * 收银台
     */
    @Select("SELECT t1.*, t2.*,t3.*  FROM SP_ORDER t1 LEFT JOIN sp_goods t2 ON t1.TB_GOODSID =t2.ID LEFT JOIN SYS_USER t3 ON  t1.TB_SELLER = t3.username   WHERE t1.ID = #{ID}")
    List<Map> SytOrder (String ID);
    /**
     * 个人中心
     */
    @Select("SELECT * FROM SYS_USER  WHERE username =#{username}")

    List<Map> Selectmember (String username);
    /**
     * 个人中心佣金
     */
    @Select("SELECT sum(TB_YJ_PRICE) FROM SP_YONGJIN  WHERE TB_YJ_USER =#{username}")
    Integer SelectmemberYj (String username);
    /**
     * 登陆人数
     */
    @Select("SELECT count(1) FROM SP_USER  WHERE username =#{username}")
    Integer userNum (String username);
    /**
     * 我的地址
     */
    @Select("SELECT * FROM SP_address  WHERE FK_ID =#{username}")
    List<Map> SelectAddress (String username);
    /**
     * 我的地址
     */
    @Select("SELECT * FROM SYS_USER  WHERE username =#{username}")
    List<Map> yjls1 (String username);

    @Select("SELECT TB_BZJ_PRICE FROM SYS_USER  WHERE username =#{username}")
    double tixian (String username);

    /**
 * 重新上架
 */
@Update(" UPDATE  SP_ORDER SET  TB_ORDER_STATE = '4' WHERE   tb_number  = #{tbgoodsid}  ")
 Boolean cxsj (String tbgoodsid);
    /**
     * 确认收货
     */
    @Update("  UPDATE  SP_ORDER SET  TB_ORDER_STATE = '3' WHERE   TB_BUYER = #{username} AND TB_NUMBER =#{ID} ")
    Boolean cxsj1 (String username,String ID);

    /**
     * 我的地址
     */
    @Update("  UPDATE  SP_ORDER SET  TB_ORDER_STATE = '3' WHERE   TB_BUYER = #{username} AND TB_NUMBER =#{ID} ")
    int shouhuo (String username,String ID);
    /**
     * jiaoyiwanc
     */
    @Update("  UPDATE  SP_ORDER SET  TB_ORDER_STATE = '3' WHERE   ID = #{id}  ")
    boolean jywc ( String ID);

    @Update(" UPDATE  SYS_USER SET  TB_BZJ_PRICE = #{jy} , GMCS = #{cs}  WHERE   USERNAME = #{name}  ")
    boolean yjls ( double jy,String name,String cs);
    @Select(" Select TB_BZJ_PRICE from   SYS_USER   WHERE   USERNAME = #{name}  ")
    double cxyjls ( String name);

    @Update(" UPDATE  SYS_USER SET  TB_BZJ_PRICE = #{jy}  WHERE   USERNAME = #{name}  ")
    boolean tixian2 ( double jy,String name);
    /**
     * 确认收货
     */
    @Update("  UPDATE  SP_ORDER SET  TB_ORDER_STATE = '3' WHERE   TB_BUYER = #{username} AND TB_NUMBER =#{ID} ")
    Boolean qrsh (String username,String ID);
    /**
     * 确认收货
     */
    @Update("  UPDATE  SP_ORDER SET  TB_ORDER_STATE = '4' WHERE   TB_NUMBER = #{tbgoodsid} ")
    Boolean cxsjzt (String tbgoodsid);
    /**
     * 更改地址
     */
    @Select("UPDATE SP_Address SET TB_DIQU =#{region}  ,TB_ADDRESS=#{detailedAddress} ,TB_USERNAME =#{name},TB_PHONE= #{phone}  ,TB_YZBM = #{postalCode} WHERE FK_ID =#{username}")
  Boolean UpAddress (String name,String phone,String region,String detailedAddress,String postalCode, String username);


}
